#! /usr/bin/env python
#coding=utf-8
import base_object
import t_mapmgr, t_const
import iworld2d

inst = None
def init():
	global inst
	if not inst:
		inst = CCamera()

def destroy():
	global inst
	if inst:
		inst.destroy()
		inst = None
		
def update():
	if inst:
		inst.update()
	pass

#游戏中逻辑管理类
class CCamera(base_object.CObject):
	def __init__(self):
		pass
	
	def destroy(self):
		pass
		
	def update(self):
		if not t_mapmgr.inst.objMe:
			return
		# 跟随玩家移动
		pos_x,pos_y = t_mapmgr.inst.objMe.obj.pos
		camera_x,camera_y = iworld2d.camera_to_worldpos(0,0)
		pos = (pos_x - t_const.GAME_WIDTH / 2, pos_y - t_const.GAME_HEIGHT / 2)
		iworld2d.camera_world_pos(pos[0],pos[1])		
		pass
